package com.siwei.mes.entity.experiment.concreteAdmixture;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.entity.experiment.slag.SlagSsl;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 外加剂-减水率
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/07/24 17:29
 */
@Data
@Accessors(chain = true)
public class ConcreteAdmixtureJSL {
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "水泥")
    private String sn = "";
    @ApiModelProperty(value = "砂")
    private String sha = "";
    @ApiModelProperty(value = "石")
    private String shi = "";
    @ApiModelProperty(value = "外加剂")
    private String wjj = "";
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")
    private String dxjl = "";
    @ApiModelProperty(value = "减水率信息")
    private List<JslList> jslList = Collections.singletonList(new ConcreteAdmixtureJSL.JslList()) ;

    @Data
    @Accessors(chain = true)
    @ApiModel("减水率信息")
    public static class JslList {
        @ApiModelProperty(value = "受检配合比水")
        private String sjphbs = "";
        @ApiModelProperty(value = "受检实测坍落度")
        private String sjsctld = "";
        @ApiModelProperty(value = "基准配合比水")
        private String jzphbs = "";
        @ApiModelProperty(value = "基准实测坍落度")
        private String jzsctld = "";
        @ApiModelProperty(value = "减水率")
        private String jsl = "";
        @ApiModelProperty(value = "基准混凝土用水量")
        private String jzhntysl = "";
        @ApiModelProperty(value = "受检混凝土用水量")
        private String sjhntysl = "";
    }
    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        ConcreteAdmixtureJSL entity = new ConcreteAdmixtureJSL();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteAdmixtureJSL.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteAdmixtureJSL.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteAdmixtureJSL entity = JsonUtils.getObject(objJson, ConcreteAdmixtureJSL.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

    public static void setValue(ConcreteAdmixtureJSL entity, Map<String, Object> data) {
        if(data.get("AVGJSL") != null){
            entity.setPjz(data.get("AVGJSL").toString());
        }
        List<ConcreteAdmixtureJSL.JslList> jslList = entity.getJslList();
        if (jslList == null) {
            jslList = new ArrayList<>();
            entity.setJslList(jslList);
        }

        // 修改第一个JslList
        if (jslList.size() > 0) {
            ConcreteAdmixtureJSL.JslList jsl = jslList.get(0);
            if (data.get("S1M2") != null) {
                jsl.setSjphbs(data.get("S1M2").toString());
            }
            if (data.get("S1M1") != null) {  // 这里应该是S1M1而不是S1M2
                jsl.setJzphbs(data.get("S1M1").toString());
            }
            if (data.get("S1JSL") != null) {
                jsl.setJsl(data.get("S1JSL").toString());
            }
        } else {
            ConcreteAdmixtureJSL.JslList jsl = new ConcreteAdmixtureJSL.JslList();
            if (data.get("S1M2") != null) {
                jsl.setSjphbs(data.get("S1M2").toString());
            }
            if (data.get("S1M1") != null) {  // 这里应该是S1M1而不是S1M2
                jsl.setJzphbs(data.get("S1M1").toString());
            }
            if (data.get("S1JSL") != null) {
                jsl.setJsl(data.get("S1JSL").toString());
            }
            jslList.add(jsl);
        }

        // 修改第二个JslList
        if (jslList.size() > 1) {
            ConcreteAdmixtureJSL.JslList jslTwo = jslList.get(1);
            if (data.get("S2M2") != null) {
                jslTwo.setSjphbs(data.get("S2M2").toString());
            }
            if (data.get("S2M1") != null) {
                jslTwo.setJzphbs(data.get("S2M1").toString());
            }
            if (data.get("S2JSL") != null) {
                jslTwo.setJsl(data.get("S2JSL").toString());
            }
        } else {
            ConcreteAdmixtureJSL.JslList jslTwo = new ConcreteAdmixtureJSL.JslList();
            if (data.get("S2M2") != null) {
                jslTwo.setSjphbs(data.get("S2M2").toString());
            }
            if (data.get("S2M1") != null) {
                jslTwo.setJzphbs(data.get("S2M1").toString());
            }
            if (data.get("S2JSL") != null) {
                jslTwo.setJsl(data.get("S2JSL").toString());
            }
            jslList.add(jslTwo);
        }

        // 修改第三个JslList
        if (jslList.size() > 2) {
            ConcreteAdmixtureJSL.JslList jslThree = jslList.get(2);
            if (data.get("S3M2") != null) {
                jslThree.setSjphbs(data.get("S3M2").toString());
            }
            if (data.get("S3M1") != null) {  // 这里应该是S3M1而不是S3M2
                jslThree.setJzphbs(data.get("S3M1").toString());
            }
            if (data.get("S3JSL") != null) {
                jslThree.setJsl(data.get("S3JSL").toString());
            }
        } else {
            ConcreteAdmixtureJSL.JslList jslThree = new ConcreteAdmixtureJSL.JslList();
            if (data.get("S3M2") != null) {
                jslThree.setSjphbs(data.get("S3M2").toString());
            }
            if (data.get("S3M1") != null) {  // 这里应该是S3M1而不是S3M2
                jslThree.setJzphbs(data.get("S3M1").toString());
            }
            if (data.get("S3JSL") != null) {
                jslThree.setJsl(data.get("S3JSL").toString());
            }
            jslList.add(jslThree);
        }
    }
}
